package com.bcu.cn.onlineexamsystem.studentmanage.controller;

import com.bcu.cn.onlineexamsystem.studentmanage.entity.StudentExamInfo;
import com.bcu.cn.onlineexamsystem.studentmanage.service.StudentExamInfoService;
import com.bcu.cn.onlineexamsystem.user.entity.User;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/student/exam")
public class StudentExamInfoController {

    @Autowired
    private StudentExamInfoService studentExamInfoService;

    @GetMapping("/list")
    public String getExamList(HttpSession session, Model model) {
        // 从session获取当前登录用户信息
        User user = (User) session.getAttribute("user");
        if (user == null || !"student".equals(user.getRole())) {
            return "redirect:/login";
        }

        // 获取学生的考试信息列表
        List<StudentExamInfo> examList = studentExamInfoService.getStudentExamInfoList(user.getUserId());
        for (StudentExamInfo exam : examList) {
            System.out.println(exam.getExamName());
            System.out.println(exam.getCourseName());
            System.out.println(exam.getExamType());
            System.out.println(exam.getStartTime());
            System.out.println(exam.getEndTime());
            System.out.println(exam.getDuration());
            System.out.println(exam.getTotalScore());
            System.out.println(exam.getStatus());
        }
        model.addAttribute("examList", examList);
        
        return "student/exam/list";
    }
} 